<template>
  <div id="login">
    <div class="login_img">

    </div>
    <div class="login_con">
      <div class="login_form">
        <h3>登录</h3>
        <el-form :label-position="labelPosition" :model="form">
          <el-form-item>
            <el-input class="phone" prefix-icon="el-icon-user-solid" v-model="form.userAccount" placeholder="请输入账号">
            </el-input>

          </el-form-item>
          <el-form-item>
            <el-input
                :type="passwordType"
                prefix-icon="el-icon-s-goods"
                :suffix-icon="passwordVisible ? 'el-icon-view' : 'el-icon-hide'"
                v-model="form.userPassword"
                placeholder="请输入密码"
                @click.native="togglePasswordVisibility"
            >
            </el-input>
          </el-form-item>

          <el-form-item>

            <el-button class="login" round type="primary" @click="login">登录</el-button>
          </el-form-item>
        </el-form>
        <div @click="$router.push('/register')"  style="color: white;">去注册用户</div>
        <!-- 使用element-ui定义form表单，在样式上做一些调整 -->
      </div>
    </div>
  </div>
</template>
<script>
import { login ,login1} from '@/http/user.js'
import { mapActions } from 'vuex'
export default {
  data() {
    return {
      labelPosition: "right",
      radio:1,
      form: {
        userAccount: "wangliang",
        userPassword: "12345678",
      },
      passwordVisible: false
      // 定义data对象form，用来保存phone和code
    };
  },
  computed: {
    passwordType() {
      return this.passwordVisible ? 'text' : 'password';
    }
  },
  methods: {
    togglePasswordVisibility() {
      this.passwordVisible = !this.passwordVisible;
    },
    ...mapActions(['user/getUserInfo', "address/getAddressInfo"]),
    async login() {
      let res = null
      res = await login(this.form)
      this['user/getUserInfo'](res.data)
      if (res.code === 0) {
        this.$message({
          message: "登录成功",
          type: "success",
        });
        if (res.data.userRole === "admin" ){
          this.$router.push("/admin/notice")
        } else if (res.data.userRole === 'teacher') {
          this.$router.push("/admin1/notice")
        }else {
          this.$router.push("/consumer/notice")
        }
      } else {
        this.$message({
          message: "登录失败",
          type: "error",
        });
      }

    },
  },
};
</script>
<style lang="scss" scope>
body,
html {
  width: 100%;
  height: 100%;
}

#login {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: left;
  align-items: center;
  min-height: 550px;
  min-width: 1200px;

  .login_img {
    height: 100%;
    width: 65%;

    position: absolute;


    /* left: 0px; */

    .login_tit {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 145px; /* 根据需要调整高度 */




      .login_tit div {
        flex: 1;
        background-color: #f0f4f8; /* 浅灰色背景 */
      }

      .login_tit div:nth-child(2) {
        font-size: 24px; /* 字体大小 */
        font-weight: bold; /* 加粗 */
        color: #1552cb; /* 深色字体 */
        text-align: center; /* 文本居中 */
      }
      div:nth-child(1) {
        width: 0;
        height: 0;
        //border-bottom: 50px solid #16dcb8;
        border-left: 30px solid transparent;
      }

      div:nth-child(2) {
        //background: url(../assets/img/xingxing.jpg);
        width: 500px;
        text-align: center;
        line-height: 50px;
        border-radius: 100px; /* 添加圆角边框 */
        color: #084f6b;/* 字体颜色 */
        font-family: 'Arial', sans-serif; /* 字体 */
        font-size: 2em; /* 字体大小 */
        font-weight: bold; /* 加粗 */
        letter-spacing: 2px; /* 字间距 */
      }

      div:nth-child(3) {
        width: 0;
        height: 0;
        //border-top: 50px solid #16dcb8;
        border-right: 30px solid transparent;
      }
    }
  }

  .login_con {
    width: 100%;
    height: 100%;

    overflow: hidden;
    background-image: url(../assets/img/login2.jpg);
    background-size: cover;
    .login_form {
      width: 300px;
      float: right;

      margin-right: 220px;
      margin-top: 170px;

      h3 {
        width: 120px;
        font-size: 22px;
        color: #0798d2;
        border-bottom: 2px solid #0798d2;
        padding-bottom: 20px;
        margin-bottom: 30px;
        font-weight: normal;
      }

      h4 {
        font-size: 15px;
        color: #30c0e0;
        font-weight: normal;
        padding-left: 10px;
        margin-top: -7px;
      }

      .el-input__inner {
        border-radius: 20px;
      }

      .el-button.login {
        width: 100%;
        background: #30c0e0;
        margin-top: 25px;
        border: none;
      }

      .phone {
        width: 65%;
      }

      .getnum {
        width: 90px;
        font-size: 12px;
        background: #30c0e0;
        padding: 12px;
        margin-left: 5px;
      }
      .el-form-item .el-input {
        width: 100%; /* 或者设置一个固定的宽度，例如 300px */
      }
    }
  }
}
</style>
